
import 'package:yp/services/api.dart';
import 'package:get/get.dart';
import 'package:sp_util/sp_util.dart';

import 'state.dart';

class MyWelfareCardListLogic extends GetxController {
  final MyWelfareCardListState state = MyWelfareCardListState();

  @override
  void onInit() {
    // TODO: implement onInit
    super.onInit();
    getEfficientWelfareCardList();
    getInvalidationWelfareCardList();
  }

  /// 获取有效福利卡列表
  void getEfficientWelfareCardList() {
    Map<String, dynamic> params = {
      "use_platform": 2,
      "usr_num_id": SpUtil.getInt('empeNumId'),
      "card_status": 1,
      "access_token": SpUtil.getString('token'),
    };

    Api.getWelfareCardList(params).listen((event) {
      print("获取有效福利卡列表==========$event");
      if (event["code"] == 0) {
        if (event["valid_cards"] != null) {
          state.efficientWelfareCardList = event["valid_cards"];
        } else {
          state.efficientWelfareCardList = [];
        }
        update();
      }
    });
  }

  /// 获取失效福利卡列表
  void getInvalidationWelfareCardList() {
    Map<String, dynamic> params = {
      "use_platform": 2,
      "usr_num_id": SpUtil.getInt('empeNumId'),
      "card_status": 2,
      "access_token": SpUtil.getString('token'),
    };

    Api.getWelfareCardList(params).listen((event) {
      print("获取失效福利卡列表==========$event");
      if (event["code"] == 0) {
        if (event["invalid_cards"] != null) {
          state.invalidationWelfareCardList = event["invalid_cards"];
        } else {
          state.invalidationWelfareCardList = [];
        }
        update();
      }
    });
  }

}
